package com.yl.auth.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yl.auth.model.entity.XingZhengChaFang;
import com.yl.auth.model.entity.XingZhengChaFangXiangQing;
import com.yl.auth.model.vo.XingZhengChaFangVo;
import com.yl.auth.service.XingZhengChaFangService;
import com.yl.common.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author L
 * @since 2023-06-27
 */
@Api(tags = "行政查房查房人管理")
@RestController
@RequestMapping("/admin/yanglao/xingzhengchafang")
public class XingZhengChaFangController {

    @Resource
    private XingZhengChaFangService xingZhengChaFangService;

    @ApiOperation("全查+分页+条件查询")
    @GetMapping("/findAllConAndPage/{page}/{limit}")
    public Result findAllConAndPage(@PathVariable Integer page,
                                    @PathVariable Integer limit,
                                    XingZhengChaFangVo xingZhengChaFangVo){
        Page<XingZhengChaFang> page1 = new Page<>(page,limit);
        LambdaQueryWrapper<XingZhengChaFang> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        String name = xingZhengChaFangVo.getName();
        String writeTime = xingZhengChaFangVo.getWriteTime();
        if (xingZhengChaFangVo!=null){
            if (!StringUtils.isEmpty(name)){
                lambdaQueryWrapper.like(XingZhengChaFang::getName,name);
            }
            if (!StringUtils.isEmpty(writeTime)){
                lambdaQueryWrapper.like(XingZhengChaFang::getWriteTime,writeTime);
            }
        }
        lambdaQueryWrapper.orderByDesc(XingZhengChaFang::getId);
        Page<XingZhengChaFang> xingZhengChaFangPage = xingZhengChaFangService.page(page1,lambdaQueryWrapper);
        return Result.ok(xingZhengChaFangPage);
    }

    @ApiOperation("新增行政查房人")
    @PostMapping("/save")
    public Result save(@RequestBody XingZhengChaFang xingZhengChaFang){
        xingZhengChaFangService.save(xingZhengChaFang);
        return Result.ok();
    }
    @ApiOperation("修改行政查房人信息")
    @PostMapping("/update")
    public Result update(@RequestBody XingZhengChaFang xingZhengChaFang){
        xingZhengChaFangService.updateById(xingZhengChaFang);
        return Result.ok();
    }

    @ApiOperation("删除行政查房人信息")
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        xingZhengChaFangService.removeById(id);
        return Result.ok();
    }
}

